Home

Computer science

'

Functions can be used to replace multiple code statements. This occurs in the Tic-Tac-Toe game program within the tutorial 2.3.5 \ufeffFinishing the Tic-Tac-Toe Program; see the printBoard function created there as an example.
What if we wanted to replace the following lines in the Tic-Tac-Toe game:
\ufeff
while (col < 1 \ufeffor col > 3):
\ufeffcol = \ufeffint(input(playerTurn + " \ufeffplayer, select a column 1-3"))
\ufeffif (col < 1 \ufeffor col > 3):
\ufeff print("The column must be between 1 \ufeffand 3.")
with a function called turn. For the call to this function, we could use:
\ufeff
col = \ufeffturn("column", \ufeffplayerTurn) \ufeff
\ufeff
where we input into the function that we want to select a column ("column") \ufeffand which player is making this selection (playerTurn).
Which code segment properly implements this function?
A.
def turn(col_row, player):
\ufeffgood_selection = \ufeffFalse
\ufeffwhile (good_selection == \ufeffFalse):
\ufeff col_row_picked = \ufeffint(input(playerTurn + " \ufeffplayer, select a {} 1-3".format(col_row)))
\ufeff if (col_row_picked < 1 \ufeffor col_row_picked > 3):
\ufeff print("The {} \ufeffmust be between 1 \ufeffand 3.".format(col_row))
\ufeff else:
\ufeff good_selection = \ufeffTrue
\ufeff return col_row
B.
def turn(col_row, player):
\ufeffgood_selection = \ufeffTrue
\ufeffwhile (good_selection == \ufeffFalse):
\ufeff col_row_picked = \ufeffint(input(playerTurn + " \ufeffplayer, select a {} 1-3".format(col_row)))
\ufeff if (col_row_picked < 1 \ufeffor col_row_picked > 3):
\ufeff print("The {} \ufeffmust be between 1 \ufeffand 3.".format(col_row))
\ufeff else:
\ufeff good_selection = \ufeffTrue
\ufeff return col_row_picked
C.
def turn(col_row, player):
\ufeffgood_selection = \ufeffTrue
\ufeffwhile (good_selection == \ufeffFalse):
\ufeff col_row_picked = \ufeffint(input(playerTurn + " \ufeffplayer, select a {} 1-3".format(col_row)))
\ufeff if (col_row_picked < 1 \ufeffor col_row_picked > 3):
\ufeff print("The {} \ufeffmust be between 1 \ufeffand 3.".format(col_row))
\ufeff else:
\ufeff good_selection = \ufeffTrue
\ufeff return col_row
D.
def turn(col_row, player):
\ufeffgood_selection = \ufeffFalse
\ufeffwhile (good_selection == \ufeffFalse):
\ufeff col_row_picked = \ufeffint(input(playerTurn + " \ufeffplayer, select a {} 1-3".format(col_row)))
\ufeff if (col_row_picked < 1 \ufeffor col_row_picked > 3):
\ufeff print("The {} \ufeffmust be between 1 \ufeffand 3.".format(col_row))
\ufeff else:
\ufeff good_selection = \ufeffTrue
\ufeff return col_row_picked
'

Answer